
from meta_service.store import ArxivPaper,GetAllEntryIds
from .export import GetFullPdfPath
from meta_service.tag import ArxivTag

def SelectByKeyWords(keyw:list=["decode","decoding"]):
    selected_entry_id = set()
    entry_ids = GetAllEntryIds()
    # print(entry_ids)
    for entry_id in entry_ids:
        paper = ArxivPaper(entry_id)
        summary = paper.get_summary()
        for key in keyw:
            if key in summary:
                selected_entry_id.add(entry_id)
                break
    # print(selected_entry_id)
    return selected_entry_id

def ListSelectedKeyw(keyw:list=["decode","decoding"]):
    selected_entry_id = SelectByKeyWords(keyw)
    for entry_id in selected_entry_id:
        # print(entry_id)
        print(GetFullPdfPath(entry_id))

def SelectByTag(tag_key:str,tag_value:str):
    selected_entry_id = set()
    entry_ids = GetAllEntryIds()
    # print(entry_ids)
    for entry_id in entry_ids:
        tag = ArxivTag(entry_id)
        if tag.HasTag(tag_key) and tag.GetTag(tag_key) == tag_value:
            selected_entry_id.add(entry_id)
    selected_entry_id = list(selected_entry_id)
    return selected_entry_id

def ListSelectedTag(tag_key:str,tag_value:str):
    selected_entry_id = SelectByTag(tag_key,tag_value)
    for entry_id in selected_entry_id:
        print(GetFullPdfPath(entry_id))

def ListSelectedTagInPapers(papers:list[str],tag_key:str,tag_value:str):
    selected_entry_id = set()
    for entry_id in papers:
        tag = ArxivTag(entry_id)
        if tag.HasTag(tag_key) and tag.GetTag(tag_key) == tag_value:
            selected_entry_id.add(entry_id)
    selected_entry_id = list(selected_entry_id)
    return selected_entry_id
